<?php


namespace App\Repositories\Lottery;

use App\Traits\Singleton;
use App\Models\MainDB\Lottery\Pool as Model;
use Illuminate\Support\Collection;

class PoolRepository
{
    use Singleton;

    // 获取总投入产出
    public function getTotalInputOutput(array $condition = [])
    {
        $pools         = $this->all($condition);
        $model         = Collection::make([]);
        $model->input  = $pools->sum('input');                                     // 总投入
        $model->output = $pools->sum('output');                                    // 总产出
        $model->rate   = $model->output == 0 ? 0 : $model->input / $model->output; // 总投入产出比
        return $model;
    }

    public function all(array $condition = [])
    {
        $query = Model::query();
        $query->where($condition);
        $models = $query->get();
        return $models;
    }
}